home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
apps
/
other
/
xxxxs.lzh
/
XXXX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-22
|
3KB
|
166 lines
#include <tos.h>
#include <stdio.h>
#include <stdlib.h>
#include <ext.h>
#include <string.h>
#include <mydefs.h>
long findx(
char *buf,
long p,
int n,
long l)
{
long q,i;
int flag;
for(q=p;q<l;q++)
{
if (*(buf+q)=='X')
{
flag=1;
for(i=0L;i<(long)n;i++)
if (*(buf+q+i)!='X')
flag=0;
if (flag)
return(q);
}
}
return(q);
}
void doit(
char *name,
long l,
int s,
int c,
int x,
int d)
{
char *sbuf;
char *dbuf;
int i,e;
long p;
int fd;
int f=0;
char *xs="%nd";
*(xs+1)=x+'0';
sbuf = malloc(l);
dbuf = malloc(l);
if (dbuf==NULL)
{
puts("\007 Not enough memory!");
if (sbuf!=NULL)
free(sbuf);
exit(-1);
}
fd=Fopen(name,READ);
if (fd<0)
{
puts("\007 Error opening file!");
exit(-3);
}
Fread(fd,l,sbuf);
Fclose(fd);
memcpy(dbuf,sbuf,l);
for(e=d,p=0L,i=s;i<s+c;i++)
{
printf("%6d%s",i,"\010\010\010\010\010\010");
p=findx(dbuf,p,x,l);
if (p>=l)
{
if (i==s)
{
puts("\007 XXXXs sequence not found in file");
exit(-2);
}
else
{
*(name+strlen(name)-5L)=(f%10)+'0';
*(name+strlen(name)-6L)=(f/10)%10+'0';
*(name+strlen(name)-7L)=(f/100)%10+'0';
++f;
puts(name);
fd=Fcreate(name,0);
Fclose(fd);
fd=Fopen(name,WRITE);
Fwrite(fd,l,dbuf);
Fclose(fd);
p=0L;
memcpy(dbuf,sbuf,l);
}
}
else
{
sprintf(dbuf+p,xs,i);
--e;
if (e==0)
e=d;
else
--i;
}
}
*(name+strlen(name)-5L)=(f%10)+'0';
*(name+strlen(name)-6L)=(f/10)%10+'0';
*(name+strlen(name)-7L)=(f/100)%10+'0';
fd=Fcreate(name,0);
Fclose(fd);
fd=Fopen(name,WRITE);
Fwrite(fd,l,dbuf);
Fclose(fd);
}
int main(
int argc,
char **argv,
char *shellp)
{
int start = 1000;
int count = 250;
int xxxxs = 4;
int dupli = 2;
char name[128];
DTA *dta;
puts("XXXX Counter 1.0 -- (C)1990 Spieu!soft");
if ((argc<2)||((argc>2)&&(argc!=6)))
{
puts("\007 Error: file name missing");
puts("--------------------------------------");
puts("filename.ext [-start -count -XXXXs -duplicates]");
puts("Replaces XXXXs with incremental valuse");
puts("e.g. xxxx -1000 -250 -4 -2 thistext.doc");
puts(" or xxxx thistext.doc");
puts("--------------------------------------");
puts("defaults-");
puts(" start: 1000");
puts(" count: 250");
puts(" XXXXs: 4");
puts(" dupl.: 2");
return(-1);
}
if (argc >2)
{
start=atoi(argv[3]+1);
count=atoi(argv[4]+1);
xxxxs=atoi(argv[5]+1);
dupli=atoi(argv[6]+1);
}
strcpy(name,argv[1]);
if (Fsfirst(name,0)>=0)
{
dta = Fgetdta();
strncpy(name,argv[1],128);
doit(name,dta->d_length,start,count,xxxxs,dupli);
}
else
{
puts(name);
puts("\007 Error: file not found!");
}
return(0);
}